package com.springboot1.controller;

import com.springboot1.pojo.Users;
import com.springboot1.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
public class UsersController {
    @Autowired
    private UsersService usersService;

    @RequestMapping("/index")
    @ResponseBody
    public List<Users> index(){

        return usersService.getUsersList();
    }

    @RequestMapping("/index2")
    @ResponseBody
    public Users index(@RequestParam("id") Integer id){

        return usersService.getUsersById(id);
    }

    @RequestMapping("/users")
    public String users(Model model){
        List<Users> list =usersService.getUsersList();
        model.addAttribute("list",list);
        return "index";
    }
}
